<div [@routerTransition]>
  <div class="m-subheader">
    <div class="d-flex align-items-center">
      <div class="mr-auto col-xs-6">
        <h3 class="m-subheader__title m-subheader__title--separator">
          <span>月度计划准备</span>
        </h3>
        <span class="m-section__sub"> 管理月度计划的文本头信息 </span>
      </div>
      <div class="col-xs-6 text-right">
        <button
          (click)="importMonthReady()"
          *ngIf="permission.isGranted('Pages.Readytasks.ZhunBei')"
          class="btn btn-success green"
          [buttonBusy]="anyncing"
          [busyText]="'同步中...'"
        >
          <i class="fa fa-refresh"></i> 同步生产准备
        </button>
      </div>
    </div>
  </div>
  <div class="m-content">
    <div class="m-portlet m-portlet--mobile">
      <div class="m-portlet__body">
        <div class="tabbable-line">
          <ul class="nav nav-tabs m-tabs-line">
            <li *ngFor="let tab of tabs" class="nav-item m-tabs__item">
              <a
                href="#tab-model"
                data-toggle="tab"
                class="nav-link m-tabs__link"
                (click)="tabTypeClick(tab.tabType.value)"
                [ngClass]="{ active: tab.tabType.isSelected }"
              >
                {{ tab.tabType.displayText }}
                <span class="badge {{ tab.tabBadgeColor }}">{{
                  tab.tabBadgeCount
                }}</span>
              </a>
            </li>
            <div style="width: 200px; display: inline-block; margin-left: 40px">
              <p-calendar
                (click)="getTabs()"
                [(ngModel)]="planDate"
                view="month"
                dateFormat="yy-mm"
                [showIcon]="true"
                name="planDate"
                [inputStyle]="{ width: '126px' }"
              ></p-calendar>
            </div>
          </ul>
          <div class="tab-content" style="padding-top: 0">
            <div class="tab-pane active" id="tab-model">
              <form class="horizontal-form" autocomplete="off">
                <div class="m-form m-form--label-align-right">
                  <div class="row align-items-center m--margin-bottom-10">
                    <div class="col-xl-12">
                      <div class="form-group m-form__group align-items-center">
                        <div class="input-group">
                          <input
                            [(ngModel)]="filterText"
                            name="filterText"
                            autofocus
                            class="form-control m-input"
                            [placeholder]="l('SearchWithThreeDot')"
                            type="text"
                          />
                          <span class="input-group-btn">
                            <button
                              (click)="getMonths()"
                              class="btn btn-primary"
                              type="submit"
                            >
                              <i
                                class="flaticon-search-1"
                                [attr.aria-label]="l('Search')"
                              ></i>
                            </button>
                          </span>
                        </div>
                      </div>
                    </div>
                  </div>

                  <div
                    class="row margin-bottom-10"
                    *ngIf="advancedFiltersAreShown"
                  >
                    <div class="col-sm-12 text-right">
                      <button class="btn btn-metal" (click)="getMonths()">
                        <i class="fa fa-refresh"></i> {{ l("Refresh") }}
                      </button>
                    </div>
                  </div>
                  <div class="row margin-bottom-10">
                    <div class="col-sm-12">
                      <span
                        class="clickable-item text-muted"
                        *ngIf="!advancedFiltersAreShown"
                        (click)="
                          advancedFiltersAreShown = !advancedFiltersAreShown
                        "
                      >
                        <i class="fa fa-angle-down"></i>
                        {{ l("ShowAdvancedFilters") }}</span
                      >
                      <span
                        class="clickable-item text-muted"
                        *ngIf="advancedFiltersAreShown"
                        (click)="
                          advancedFiltersAreShown = !advancedFiltersAreShown
                        "
                      >
                        <i class="fa fa-angle-up"></i>
                        {{ l("HideAdvancedFilters") }}</span
                      >
                    </div>
                  </div>
                </div>
              </form>

              <div class="row align-items-center">
                <div
                  class="primeng-datatable-container"
                  [busyIf]="primengTableHelper.isLoading"
                >
                  <div class="m-month">
                    <div class="table-responsive" style="min-height: 600px">
                      <table class="table" id="pipe-table" #dataTable>
                        <thead>
                          <tr>
                            <td class="m-pipeline__action">操作</td>
                            <td class="m-pipeline__base">基础信息</td>
                            <td class="m-pipeline__time">工艺信息</td>
                            <td class="m-pipeline__status">材料信息</td>
                            <td class="m-pipeline__status">工装信息及状态</td>
                            <td class="m-pipeline__action">调度员处理(备注)</td>
                          </tr>
                        </thead>
                        <tbody>
                          <tr *ngFor="let task of primengTableHelper.records">
                            <td *ngIf="
                            isGrantedAny(
                              'Pages.Readytasks.Tech',
                              'Pages.Readytasks.Tool',
                              'Pages.Readytasks.Material'
                            )
                          ">
                              <div
                                class="btn-group dropdown"
                                dropdown
                                container="body"
                              >
                                <button
                                  dropdownToggle
                                  class="dropdown-toggle btn btn-sm btn-primary"
                                >
                                  <i class="fa fa-cog"></i
                                  ><span class="caret"></span>
                                  操作
                                </button>
                                <ul class="dropdown-menu" *dropdownMenu>
                                  <!-- <li
                                    *ngIf="isGranted('Pages.Maintasks.PutInto')"
                                  >
                                    <a
                                      (click)="
                                        putIntoProductionModal.showMonth(
                                          task.taskId,
                                          task.id,
                                          $event
                                        )
                                      "
                                      >投产</a
                                    >
                                  </li> -->
                                  <li *ngIf="isGranted('Pages.Readytasks.Tech')">
                                    <a
                                      (click)="
                                        boundReadytechdoc.show(
                                          task.id,
                                          task.techDocCode,
                                          task.drawingCode,
                                          $event
                                        )
                                      "
                                      >匹配工规</a
                                    >
                                  </li>
                                  <li *ngIf="isGranted('Pages.Readytasks.Material')">
                                    <a
                                      (click)="
                                        boundReadymaterial.show(
                                          task.id,
                                          task.techDocCode,
                                          $event
                                        )
                                      "
                                      >更改原材料</a
                                    >
                                  </li>
                                  <li *ngIf="isGranted('Pages.Readytasks.Tool')">
                                    <a
                                      (click)="
                                        boundReadytool.show(
                                          task.id,
                                          task.techDocCode,
                                          $event
                                        )
                                      "
                                      >更改工装</a
                                    >
                                  </li>
                                  <li>
                                    <a
                                      (click)="
                                        setWorkshopremark.show(
                                          task.id,
                                          task.workShopRemark,
                                          1,
                                          $event
                                        )
                                      "
                                      >录入调度备注</a
                                    >
                                  </li>
                                </ul>
                              </div>
                            </td>
                            <td>
                              <div class="row">
                                <div class="col-md-6">
                                  <span class="m-pipeline__title">
                                    {{ task.taskCode }}
                                  </span>
                                  <span class="m-pipeline__sub">
                                    计划数量：{{ task.amount }}
                                  </span>
                                  <span class="m-pipeline__sub">
                                    投产数量：{{
                                      task.amountPlanned
                                    }}&nbsp;&nbsp;&nbsp; 完成数量：{{
                                      task.amountFinished
                                    }}
                                  </span>
                                </div>
                                <div class="col-md-6">
                                  <span class="m-pipeline__title">
                                    {{ task.drawingCode }}
                                  </span>
                                  <span class="m-pipeline__sub">
                                    {{ task.taskName }}
                                  </span>
                                  <span class="m-pipeline__sub">
                                    要求完成时间：{{
                                      task.dueDate | momentFormat: "YYYY-MM-DD"
                                    }}
                                  </span>
                                </div>
                              </div>
                            </td>
                            <td>
                              <span
                                *ngIf="task.isHaveTech != true"
                                class="m-badge m-badge--success m-badge--wide"
                                >未绑定
                              </span>
                              <span *ngIf="task.isHaveTech == true"
                                >{{ task.techDocCode }}
                              </span>
                            </td>
                            <td>
                              <span
                                *ngIf="task.isHaveMaterial != true"
                                class="m-badge m-badge--success m-badge--wide"
                                >无原材料
                              </span>
                              <div *ngIf="task.isHaveMaterial == true">
                                <span
                                  class="col-md-6 m-pipeline__other"
                                  style="float: left"
                                  *ngFor="let material of task.techDocMaterials"
                                >
                                  {{ material.name }}--{{ material.grade }}--{{
                                    material.size
                                  }}
                                  <span
                                    style="color: red; display: block"
                                    *ngIf="material.isHaveStatus != true"
                                    >(缺料)</span
                                  >
                                  <span
                                    style="color: green; display: block"
                                    *ngIf="material.isHaveStatus == true"
                                    >(库存：{{ material.materialNum }})</span
                                  >
                                </span>
                              </div>
                            </td>
                            <td>
                              <span
                                *ngIf="task.isHaveTool != true"
                                class="m-badge m-badge--success m-badge--wide"
                                >无工装
                              </span>
                              <div *ngIf="task.isHaveTool == true">
                                <span
                                  style="float: left"
                                  class="col-md-6 m-pipeline__other"
                                  *ngFor="let tool of task.techDocTools"
                                >
                                  {{ tool.name }}--{{ tool.stamp }}
                                  <span
                                    style="color: yellow"
                                    *ngIf="
                                      tool.toolStatus != '在库' &&
                                      tool.toolStatus != '库中不存在'
                                    "
                                    >{{ tool.toolStatus }}
                                  </span>
                                  <span
                                    style="color: green"
                                    *ngIf="tool.toolStatus == '在库'"
                                    >({{ tool.toolStatus }})</span
                                  >
                                  <span
                                    style="color: red"
                                    *ngIf="tool.toolStatus == '库中不存在'"
                                    >({{ tool.toolStatus }})</span
                                  >
                                </span>
                              </div>
                            </td>
                            <td>
                              <span
                                *ngIf="task.workShopRemark == null"
                                class="m-badge m-badge--success m-badge--wide"
                                >无
                              </span>
                              <span *ngIf="task.isHaveTech == true"
                                >{{ task.workShopRemark }}
                              </span>
                            </td>
                          </tr>
                        </tbody>
                      </table>
                      <div class="primeng-paging-container">
                        <p-paginator
                          rows="{{
                            primengTableHelper.FiveRecordsCountPerPage
                          }}"
                          #paginator
                          (onPageChange)="getMonths($event)"
                          [totalRecords]="primengTableHelper.totalRecordsCount"
                          [rowsPerPageOptions]="
                            primengTableHelper.predefinedRecordsCountPerPage
                          "
                        >
                        </p-paginator>
                        <span class="total-records-count">
                          {{ "总计:" + primengTableHelper.totalRecordsCount }}
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <boundReadymaterial
    #boundReadymaterial
    (modalSave)="getMonths($event)"
  ></boundReadymaterial>

  <boundReadytechdoc
    #boundReadytechdoc
    (modalSave)="getMonths($event)"
  ></boundReadytechdoc>

  <setWorkshopremark
    #setWorkshopremark
    (modalSave)="getMonths($event)"
  ></setWorkshopremark>
  <boundReadytool
    #boundReadytool
    (modalSave)="getMonths($event)"
  ></boundReadytool>
</div>
